1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| #include <cstdio> #include <cmath> #include <vector> #include <algorithm> #include <set> #include <cstring> #define LL long long const int maxn = 1e6 + 5; using namespace std; LL a[maxn]; int n; vector <LL> v; void split(LL x){ v.clear(); for (LL i = 1; i * i <= x; i++){ if (x % i != 0) continue; v.push_back(i); if (i * i != x) v.push_back(x / i); } sort(v.begin(), v.end()); } LL _gcd(LL x, LL y){ return (!y) ? x : _gcd(y, x % y); } int cnt[10005]; LL ans = 0; LL max(LL x, LL y){ return x < y ? y : x; } int main(){ scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", a + i); for (int T = 0; T < 10; T++){ int u = rand() * rand() % n + 1; split(a[u]); memset(cnt, 0, sizeof cnt); for (int i = 1; i <= n; i++){ LL g = _gcd(a[i], a[u]); vector<LL>::iterator it = lower_bound(v.begin(), v.end(), g); if (it == v.end()) continue; cnt[it - v.begin()]++; } for (int i = 0; i < v.size(); i++) for (int j = i + 1; j < v.size(); j++) if (v[j] % v[i] == 0) cnt[i] += cnt[j]; for (int i = v.size() - 1; i >= 0; i--){ if (cnt[i] >= (n + 1) / 2){ ans = max(ans, v[i]); break; } } } printf("%lld\n", ans); return 0; }
|